﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Boiling.BizFacade
{
    using System;
    using System.Data;

    using Boiling.Common;
    using Boiling.DataAccess;
    
    /// <summary>
    /// 处理日志评论
    /// </summary>
    public class BlogCommentManager
    {
        
        /// <summary>
        /// 给定日志留言编号得到一条留言的方法
        /// </summary>
        /// <param name="mesid">留言编号</param>
        /// <returns></returns>
        public b_Diary_Mesdata GetDiarymesbyNo(int mesid)
        {
            return (new b_Diary_Mes()).getdiarybyNO(mesid);
        }

        /// <summary>
        /// 给定一篇日志的编号，得到其所有留言
        /// </summary>
        /// <param name="diaryid">日志编号</param>
        /// <returns></returns>
        public b_Diary_Mesdata GetDiarymesbyDiary(int diaryid)
        {
            return (new b_Diary_Mes()).getdiarymesbydiary(diaryid);
        }

        /// <summary>
        /// 给定一篇日志的编号，返回其留言数
        /// </summary>
        /// <param name="diaryid">日志编号</param>
        /// <returns></returns>
        public int GetDiarymesCountbyDiary(int diaryid)
        {
            return ((new b_Diary_Mes()).getdiarymesbydiary(diaryid).Tables["b_Diary_Mes"].Rows.Count);
        }



        /// <summary>
        /// 根据日志留言编号删除一篇留言
        /// </summary>
        /// <param name="mesid">留言编号</param>
        /// <returns></returns>
        public bool deleteDiarymesbyno(int mesid)
        {
            return (new b_Diary_Mes()).deleteDiarymesbyno(mesid);
        }

        /// <summary>
        /// 根据日志编号删除与其相关的所有留言【慎用！】
        /// </summary>
        /// <param name="diaryid">日志编号</param>
        /// <returns></returns>
        public bool DeleteDiarybyID(int diaryid)
        {
            return (new b_Diary_Mes()).deleteDiarybyID(diaryid);
        }


        /// <summary>
        /// 修改日志评论
        /// </summary>
        /// <param name="diarymesData"></param>
        /// <returns></returns>
        public bool EditDiarymes(int diaryId, String guestID, String content)
        {
            b_Diary_Mesdata diarymesData = new b_Diary_Mesdata();
            DataTable table = diarymesData.Tables[b_Diary_Mesdata.b_Diary_Mes_Table];
            DataRow row = table.NewRow();

            row[b_Diary_Mesdata.Diary_ID_Field] = diaryId;
            row[b_Diary_Mesdata.Guest_ID_Field] = guestID;
            row[b_Diary_Mesdata.Mes_Content_Field] = content;
            row[b_Diary_Mesdata.Mes_Date_Field] = System.DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒");

            table.Rows.Add(row);
            
            return (new b_Diary_Mes()).modifydiarymes(diarymesData);
        }



        /// <summary>
        /// 插入日志评论
        /// </summary>
        /// <param name="diarymesData"></param>
        /// <returns></returns>
        public bool InsertDiarymes(int diaryId, String guestID, String content)
        {
            b_Diary_Mesdata diarymesData = new b_Diary_Mesdata();
            DataTable table = diarymesData.Tables[b_Diary_Mesdata.b_Diary_Mes_Table];
            DataRow row = table.NewRow();

            row[b_Diary_Mesdata.Diary_ID_Field] = diaryId;
            row[b_Diary_Mesdata.Guest_ID_Field] = guestID;
            row[b_Diary_Mesdata.Mes_Content_Field] = content;
            row[b_Diary_Mesdata.Mes_Date_Field] = System.DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒");

            table.Rows.Add(row);

            return (new b_Diary_Mes()).insertdiarymes(diarymesData);
        }
    }
}
